package com.zhuanzhuan.hero.user.helper;

import com.bj58.youpin.common.utils.json.JsonUtils;
import com.zhuanzhuan.hero.user.pojo.bo.BmWarehouseBO;
import com.zhuanzhuan.hunter.partner.recycle.dto.report.BmWarehouseDTO;
import com.zhuanzhuan.hunter.partner.recycle.facade.report.IBmWarehouseFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName BmWarehouseHelper
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/28 13:43
 */
@Component
@Slf4j
public class BmWarehouseHelper {

    @Resource
    private IBmWarehouseFacade bmWarehouseFacade;

    /**
     * 根据uid查询绑定的保卖仓
     *
     * @param uids
     * @return java.util.List<com.zhuanzhuan.hero.user.pojo.bo.BmWarehouseBO>
     * @author  hanjunjun
     * @date 2024/6/28
     **/
    public List<BmWarehouseBO> batchGetUidOwnWarehouseInfo(List<Long> uids) {
        uids = uids.stream().distinct().collect(Collectors.toList());
        if (CollectionUtils.isEmpty(uids)) {
            return new ArrayList<>();
        }
        log.info("batchGetUidOwnWarehouseInfo param={}", JsonUtils.toJsonWithoutNull(uids));
        //k:uid v:状态启用状态的保卖仓
        Map<Long, BmWarehouseDTO> bmWarehouseMap = bmWarehouseFacade.batchGetUidOwnWarehouseInfo(uids);
        log.info("batchGetUidOwnWarehouseInfo result={}", JsonUtils.toJsonWithoutNull(bmWarehouseMap));

        return bmWarehouseMap.values().stream().map(this::convert).collect(Collectors.toList());
    }

    private BmWarehouseBO convert(BmWarehouseDTO dto) {
        if (dto == null) {
            return null;
        }
        BmWarehouseBO bmWarehouseBO = new BmWarehouseBO();
        bmWarehouseBO.setWarehouseId(dto.getWarehouseId());
        bmWarehouseBO.setWarehouseUid(dto.getWarehouseUid());
        bmWarehouseBO.setWarehouseName(dto.getWarehouseName());
        return bmWarehouseBO;
    }
}
